package com.ship.contract.bean;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ship.common.core.base.ContractBaseBean;
import com.ship.common.core.base.Joinable;
import com.ship.common.core.mapping.Label;
import com.ship.common.core.mapping.SearchItem;
import com.ship.common.core.mapping.TableColumn;
import com.ship.common.core.validate.Add;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Date;

@TableName("con_broker")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ConBroker extends ContractBaseBean implements Joinable {

    /**
     * 合同名称
     */
    @Label(value = "合同名称", multiSelect = true)
    @TableColumn
    private String contractName;

    /**
     * 执行编号
     */
    @Label(value = "执行编号")
    @TableColumn
    private String contractNumber;

    /**
     * 甲方
     */
    @Label(value = "甲方")
    @SearchItem
    @TableColumn
    private String partnerA;

    /**
     * 合作方 B
     */
    @Label(value = "乙方")
    @SearchItem
    @TableColumn
    private String partnerB;

    /**
     * 合同主体
     */
    @Label(value = "合同主体", enumContent = "贸易主体", multiSelect = true)
//    @TableColumn
    private Integer tradeBody;

    @ApiModelProperty(value = "合同主体")
    @TableField(exist = false)
    @Label(value = "合同主体", enumContent = "贸易主体", multiSelect = true)
    @TableColumn
    @SearchItem
    private String tradeBodyStr;

    /**
     * 服务费率
     */
    @Label(value = "服务费率")
    private BigDecimal serviceRate;

    @Label(value = "服务费率")
    @TableColumn
    @TableField(exist = false)
    private String serviceRateStr;

    /**
     * 银行名称
     */
    @Label(value = "银行名称")
    @TableColumn
    private String bankName;

    /**
     * 到期时间
     */
    @Label(value = "到期时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @TableColumn
    private Date expirationDate;

    /**
     * 银行地址
     */
    @Label(value = "银行地址")
    @TableColumn
    private String bankAddress;

    /**
     * 银行账户名称
     */
    @Label(value = "银行账户名称")
    @TableColumn
    private String bankAccountName;

    /**
     * 银行账户号码
     */
    @Label(value = "银行账户号码")
    @TableColumn
    private String bankAccountNumber;

    /**
     * IBAN
     */
    @Label(value = "IBAN")
    @TableColumn
    private String iban;

    /**
     * Swift Number
     */
    @Label(value = "Swift Number")
    @TableColumn
    private String swiftNumber;

    /**
     * 海油联系人邮箱
     */
    @Label(value = "海油联系人邮箱")
    @TableColumn
    private String contactEmail;

    /**
     * 状态(已签订、执行中、已完成)
     */
    @Label(value = "状态", enumContent = "经纪人合同状态")
    @SearchItem
//    @TableColumn
    private Integer status;

    @Label(value = "状态", enumContent = "经纪人合同状态")
    @SearchItem
    @TableColumn
    @TableField(exist = false)
    private String statusStr;

    /**
     * 删除申请
     */
    @Label(value = "删除申请")
    private Integer delApply;

    /**
     * 附件地址
     */
    @TableField(exist = false)
    private String filePath;

    /**
     * 优秀案例
     */
    @Label(value = "优秀案例", enumContent = "是否是优秀案例")
    private Integer excellent;

    /**
     * 签订日期
     */
    @Label(value = "签订日期")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private Date signingDate;

    @Label(value = "删除流程实例id")
    private String deleteProcessInstanceId;

    @Label(value = "付款截止日")
//    @TableColumn
    @SearchItem
    private String payOffDayStr;

    /**
     * 付款截止日类型，工作日/自然日
     */
    private Integer payDaysType;

    /**
     * tcp关联方(船运合同名称，逗号分隔)
     */
    @Label(value = "tcp关联方")
    private String tcpRelate;

    /**
     * tcp关联方id(船运合同id，逗号分隔)
     */
    private String tcpRelateId;

    /**
     * 付款截止日（文本）
     */
    private String payOffDayText;

    /**
     * 付款截止日字符串
     */
    @Label(value = "付款截止日")
    @TableColumn
    @TableField(exist = false)
    private String payOffDayAll;

    public String getPayOffDayAll() {
        String result = "";
        if (StringUtils.isNotBlank(getPayOffDayText())) {
            result += getPayOffDayText();
        }
        if (StringUtils.isNotBlank(getPayOffDayStr())) {
            result += getPayOffDayStr();
        }
        if(null != getPayDaysType()){
            if (1 == getPayDaysType()) {
                result += "工作日";
            } else if (2 == getPayDaysType()) {
                result += "自然日";
            }
        }
        return result;
    }


    public String getServiceRateStr() {
        // BigDecimal serviceRate = getServiceRate().stripTrailingZeros();
        DecimalFormat format = new DecimalFormat("0.##");
        String serviceRate = format.format(getServiceRate());
        String result = serviceRate + "%";
        return result;
    }

    public String getTradeBodyStr() {
        String tradeBodyStr = null;
        if (this.getTradeBody() != null){
            if (1 == this.getTradeBody()){
                tradeBodyStr = "国贸";
            }

            if (2 == this.getTradeBody()){
                tradeBodyStr = "新贸";
            }
        }
        return tradeBodyStr;
    }

    public String getStatusStr() {
        String statusStr = null;
        if (null != this.getStatus()){
            if (1 == this.getStatus()){
                statusStr = "草稿中";
            }
            if (2 == this.getStatus()){
                statusStr = "已签订";
            }
            if (3 == this.getStatus()){
                statusStr = "执行中";
            }
            if (4 == this.getStatus()){
                statusStr = "已完成";
            }
            if (5 == this.getStatus()){
                statusStr = "暂停中";
            }
        }
        return statusStr;
    }

    @Override
    public String getLabel() {
        return null;
    }

    @Override
    public String getValue() {
        return null;
    }
}
